From: Matthieu Gallien Date: Tue, 20 May 2025 21:35:29 +0000 (+0200) Subject: fix(readonly): ignore move to trash for read-èonly items X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1^2~13^2~1^2~37^2~1 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=3c59734da2cf0d963481802f0107222fcf3fa8f5;p=nextcloud-desktop.git fix(readonly): ignore move to trash for read-èonly items Signed-off-by: Matthieu Gallien --- diff --git a/src/libsync/propagatorjobs.cpp b/src/libsync/propagatorjobs.cpp index 272fe40b6..ca0919b5f 100644 --- a/src/libsync/propagatorjobs.cpp +++ b/src/libsync/propagatorjobs.cpp @@ -107,8 +107,35 @@ void PropagateLocalRemove::start() } QString removeError; - if (_moveToTrash && propagator()->syncOptions()._vfs->mode() != OCC::Vfs::WindowsCfApi) { - const auto fileInfo = QFileInfo{filename}; + auto moveToTrashIsFeasible = true; + if (propagator()->syncOptions()._vfs->mode() != OCC::Vfs::WindowsCfApi) { + moveToTrashIsFeasible = false; + } + const auto fileInfo = QFileInfo{filename}; + if (fileInfo.isDir()) { + try { + if (FileSystem::isFolderReadOnly(fileInfo.filesystemAbsolutePath())) { + moveToTrashIsFeasible = false; + } + } + catch (const std::filesystem::filesystem_error &e) + { + qCWarning(lcPropagateLocalRemove) << "exception when checking parent folder read only status" << e.what() << e.path1().c_str() << e.path2().c_str(); + } + catch (const std::system_error &e) + { + qCWarning(lcPropagateLocalRemove) << "exception when checking parent folder read only status" << e.what(); + } + catch (...) + { + qCWarning(lcPropagateLocalRemove) << "exception when checking parent folder read only status"; + } + } else { + if (!FileSystem::isWritable(filename, fileInfo)) { + moveToTrashIsFeasible = false; + } + } + if (_moveToTrash && moveToTrashIsFeasible) { if (FileSystem::fileExists(filename, fileInfo)) { const auto parentFolderPath = fileInfo.dir().absolutePath(); const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite}; @@ -123,12 +150,11 @@ void PropagateLocalRemove::start() } } else { if (_item->isDirectory()) { - if (FileSystem::fileExists(filename) && !removeRecursively(QString())) { + if (FileSystem::fileExists(filename, fileInfo) && !removeRecursively(QString())) { done(SyncFileItem::NormalError, tr("Temporary error when removing local item removed from server."), ErrorCategory::GenericError); return; } } else { - const auto fileInfo = QFileInfo{filename}; if (FileSystem::fileExists(filename, fileInfo)) { const auto parentFolderPath = fileInfo.dir().absolutePath(); const auto parentPermissionsHandler = FileSystem::FilePermissionsRestore{parentFolderPath, FileSystem::FolderPermissions::ReadWrite};